<br>
<br>
<br>
<div class="row">
    <div class="col-xs-12 col-md-12">
        <div class="grid simple">
            <div class="grid-body no-border">
                <form id="edit-member"> 
                    <div class="row form-row">
                        <div class="col-xs-8 col-md-4">
                            <label class="form-label">角色名</label>
                            <h4><?= $role['name'] ?></h4>
                        </div> 
                    </div> 
                    <br>
                    <div class="row form-row">
                        <div class="col-xs-8 col-md-4">
                            <label class="form-label">用户</label>
                            <select name="admins[]" class="select2" style="width:100%" multiple>
                                <? foreach($admin as $a): ?>
                                    <? if(is_array($role['admins']) && isset($role['admins'][$a['admin_id']])): ?>
                                        <? $selected = 'selected="selected"' ?>
                                    <? else: ?>
                                        <? $selected = '' ?>
                                    <? endif ?>
                                    <option <?= $selected ?> value="<?= $a['admin_id'] ?>">
                                        <?= $a['nickname'] ?>
                                    </option>
                                <? endforeach ?>
                            </select>
                        </div> 
                    </div>
                      
                    <div class="form-actions">  
                        <div class="pull-left">
                            <button class="btn btn-success btn-cons" type="button" onclick="$.Edit_member.submit()">
                                <i class="icon-save"></i>&nbsp;保存</button>
                            </button>
                            <button class="btn btn-white btn-cons" type="button" onclick="$.T.reset_form(this)">
                                重置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $.Edit_member = {
        role_id: <?= $role['role_id']?>,
        submit: function()
        {
            var form   = $('#edit-member');
            var params = form.serializeArray();
            var flag   = false;

            console.log(params);
            for (var i in params)
            {
                if(params[i]['name'] == 'admins[]')
                {
                    flag = true;
                    break;
                }
            }
            if(flag === true)
            {
                form
                    .attr('action', $.G.domain+'role/edit_member/'+$.Edit_member.role_id)
                    .attr('method', 'POST')
                    .submit();
            }
            else
            {
                $.T.confirm("您没有选择任何用户，确认要删除该角色所有用户吗？", function(){
                    form
                    .attr('action', $.G.domain+'role/del_member/'+$.Edit_member.role_id)
                    .attr('method', 'POST')
                    .submit();
                });
            }
        }
    }
</script>